import Cookies from 'js-cookie';

const app = {
  state: {
    sidebar: {
      opened: false,
      asideWidth: '200px'
    },
    device: 'desktop'
  },
  mutations: {
    // 切换菜单栏状态
    TOGGLE_SIDEBAR: state => {
      state.sidebar.opened = !state.sidebar.opened;
      if (state.sidebar.opened) {
        state.sidebar.asideWidth = '65px';
        Cookies.set('sidebarStatus', 1);
      } else {
        state.sidebar.asideWidth = '200px';
        Cookies.set('sidebarStatus', 0);
      }
    },
    // 打开菜单栏
    OPEN_SIDEBAR: (state) => {
      Cookies.set('sidebarStatus',1);
      state.sidebar.opened = true;
      state.sidebar.asideWidth = '200px';
    },
    // 关闭菜单栏
    CLOSE_SIDEBAR: (state) => {
      Cookies.set('sidebarStatus', 0);
      state.sidebar.opened = false;
      state.sidebar.asideWidth = '65px';
    },
  },
  actions: {
    toggleSideBar({ commit }) {
      commit('TOGGLE_SIDEBAR')
    }
  }
};

export default app;
